home *** CD-ROM | disk | FTP | other *** search
/ Packard Bell - Internet on a CD / internet on a cd.cdr / Internet / sites / Clementine_NASA / clemdsrc.hqx / clemdcmp_menu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-24  |  8.4 KB  |  308 lines

  1. /*********************************************************************************
  2. *
  3. *_Title  CLEMDCMP_MENU - Insert program menus and obtain user input
  4. *
  5. *_Args    Type     Variable       I/O  Description
  6. *_Parm    char     *opt            I   Menu option.  If opt=NEW, the current menu 
  7. *                                      bar will be removed and the program specific 
  8. *                                      menu bar will be in-stalled.  User input 
  9. *                                      will be obtained until either the Run option 
  10. *                                      or the Quit option is clicked on in the File
  11. *                                       menu.  If opt=OLD, the current (program 
  12. *                                      specific) menu bar will be removed and the 
  13. *                                      previous menu bar will be reinstalled.
  14. *
  15. *_Desc  Clemdcmp_menu will insert the program specific menus into the menu bar
  16. *       and obtain the user input.
  17. *
  18. *_Hist  Unknown     Janet Barrett, USGS,  Flagstaff Original Version
  19. *       Aug 12 1994 Tracie Sucharski,  Adapted for the clementine decompression
  20. *                        software
  21. *
  22. ***********************************************************************************/
  23.  
  24. /********************
  25. * Standard C includes 
  26. *********************/
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. /***************************
  32. * Macintosh toolbox includes 
  33. ****************************/
  34. #include <Packages.h>
  35.  
  36. /*****************
  37. * Global variables
  38. ******************/
  39. extern struct {
  40.   char prgnam[9];
  41.   char hlpfil[13];
  42.   char infile[128];
  43.   char outfile[128];
  44.   char img;
  45.   char format;
  46. } clemargs;
  47.  
  48. void clemdcmp_menu (char *opt)
  49. {
  50.    static Handle  mbar,ombar;
  51.    SFReply  replyi,replyo;
  52.    MenuHandle  applemenu,filemenu,parammenu,param1menu,param2menu;
  53.    EventRecord  TheEvent;
  54.    Boolean  nxtevt;
  55.    WindowPtr  theWin;
  56.    short int  thePart;
  57.    SFTypeList  types;
  58.    long int  menuChoice;
  59.    int  iflg = 0;
  60.    int  oflg = 0;
  61.    int  theMenu,theItem;
  62.    Point where = {100,50};
  63.    extern long int  resnum;
  64.    long int  winres = 440;
  65.    long int  vscres = 441;
  66.    char  *opt1 = "NEW";
  67.    char  *opt2 = "OLD";
  68.    long int istr;
  69.    
  70.    void errmsg();
  71.    void get_filename();
  72.    void scroll();
  73.    
  74.    if (*opt == *opt1) {
  75.      replyi.good = 0;
  76.      replyo.good = 0;
  77.    
  78. /*********************************
  79. * Get a handle to the old menu bar 
  80. **********************************/
  81.      ombar = GetMenuBar();
  82.    
  83. /*********************************
  84. * Get a handle to the new menu bar 
  85. **********************************/
  86.      mbar = GetNewMBar(128);
  87.    
  88. /*******************************************
  89. * Make the new menu bar the current menu bar 
  90. ********************************************/
  91.      SetMenuBar(mbar);
  92.    
  93. /*******************************
  94. * Get a handle to the apple menu 
  95. ********************************/
  96.      applemenu = GetMenu(129);
  97.    
  98. /******************************
  99. * Get a handle to the File menu 
  100. *******************************/
  101.      filemenu = GetMenu(130);
  102.      
  103. /************************************
  104. * Get a handle to the Parameters menu 
  105. *************************************/
  106.      parammenu = GetMenu(131);
  107.      param1menu = GetMenu(1);
  108.      param2menu = GetMenu(2);
  109.    
  110. /**************************************
  111. * Insert the apple menu in the menu bar 
  112. ***************************************/
  113.      InsertMenu(applemenu,0);
  114.    
  115. /*************************************
  116. * Insert the File menu in the menu bar 
  117. **************************************/
  118.      InsertMenu(filemenu,0);
  119.      
  120. /*******************************************
  121. * Insert the Parameters menu in the menu bar 
  122. ********************************************/
  123.      InsertMenu(parammenu,0);
  124.      InsertMenu(param1menu,-1);
  125.      InsertMenu(param2menu,-1);
  126.      
  127. /***********************************
  128. * Disable all appropriate menu items 
  129. ************************************/
  130.      DisableItem(filemenu,3);
  131.    
  132. /**********************
  133. * Draw the new menu bar 
  134. ***********************/
  135.      DrawMenuBar();
  136.      CheckItem(param1menu,1,true);
  137.      CheckItem(param2menu,1,true);
  138.    
  139. /********************
  140. * Handle a menu event 
  141. *********************/
  142.    
  143. /***************************
  144. * Get an event from the user 
  145. ****************************/
  146.      theMenu = 0;
  147.      theItem = 0;
  148.      while (theMenu != 130 | theItem != 3) {
  149.        nxtevt = GetNextEvent(everyEvent,&TheEvent);
  150.    
  151.        /******************
  152.     * Process the event 
  153.     *******************/
  154.        if (TheEvent.what == mouseDown || TheEvent.what == keyDown) {
  155.        
  156.      /*********************************************************************
  157.       * Determine which part of which window the mouse button was pressed in 
  158.       **********************************************************************/
  159.      thePart = FindWindow(TheEvent.where,&theWin);
  160.          
  161.      /******************************************************************
  162.       * Process the event if the mouse button was pressed in the menu bar 
  163.       *******************************************************************/
  164.      if (thePart == inMenuBar || (TheEvent.modifiers & cmdKey)) {
  165.        if (thePart == inMenuBar && TheEvent.what == mouseDown) {
  166.          menuChoice = MenuSelect(TheEvent.where);
  167.        }
  168.        else {
  169.          menuChoice = MenuKey(TheEvent.message & charCodeMask);
  170.        }
  171.             
  172.        if (menuChoice != 0) {
  173.          theMenu = HiWord(menuChoice);
  174.          theItem = LoWord(menuChoice);
  175.                
  176.      switch (theMenu) {
  177.      case 129:        /*  Apple Menu  */
  178.        switch (theItem) {
  179.        case 1:
  180.          HiliteMenu(0);
  181.          DisableItem(applemenu,0);
  182.          DisableItem(filemenu,0);
  183.          DisableItem(parammenu,0);
  184.          DrawMenuBar();
  185.          scroll(clemargs.hlpfil,clemargs.prgnam,&winres,&vscres);
  186.          EnableItem(applemenu,0);
  187.          EnableItem(filemenu,0);
  188.          EnableItem(parammenu,0);
  189.          DrawMenuBar();
  190.          break;
  191.        }
  192.        break;
  193.      case 130:     /*   File Menu   */
  194.        switch (theItem) {
  195.        case 1:
  196.          SFGetFile(where,"\p",NULL,-1,types,NULL,&replyi);
  197.          iflg = 1;
  198.          if (oflg == 1)
  199.                EnableItem(filemenu,3);
  200.          HiliteMenu(0);
  201.          break;
  202.        case 2:
  203.         SFPutFile(where,"\pOutput decompressed Clementine File",c2pstr(clemargs.outfile),
  204.                            NULL,&replyo);
  205.         get_filename(replyo,clemargs.outfile);
  206.         istr = strlen(clemargs.outfile);
  207.         while ((clemargs.outfile[istr] != ':') && (istr > -1))
  208.           istr = istr -1;
  209.         if (istr > -1)
  210.           strcpy(&(clemargs.outfile[0]),&(clemargs.outfile[istr+1]));
  211.         oflg = 1;
  212.          if (iflg == 1)
  213.              EnableItem(filemenu,3);
  214.          HiliteMenu(0);
  215.          break;
  216.        case 3:
  217.          get_filename(replyi,clemargs.infile);
  218.          get_filename(replyo,clemargs.outfile);
  219.          oflg = 1;
  220.          if (iflg == 1)
  221.                EnableItem(filemenu,3);
  222.          HiliteMenu(0);
  223.          break;
  224.        case 5:
  225.          clemdcmp_menu("OLD");
  226.          exit(0);
  227.          break;
  228.        }
  229.        break;
  230.      case 2:       /*   Output File Type   */
  231.        switch (theItem) {
  232.        case 1:
  233.          CheckItem(param2menu,1,true);
  234.          CheckItem(param2menu,2,false);
  235.          clemargs.img = 'i';
  236.          HiliteMenu(0);
  237.          break;
  238.        case 2:
  239.          CheckItem(param2menu,1,false);
  240.          CheckItem(param2menu,2,true);
  241.          clemargs.img = 'b';
  242.          HiliteMenu(0);
  243.          break;
  244.        }
  245.        break;
  246.      case 1:    /*   Output File format   */
  247.        switch (theItem) {
  248.        case 1:
  249.          CheckItem(param1menu,1,true);
  250.          CheckItem(param1menu,2,false);
  251.          CheckItem(param1menu,3,false);
  252.          CheckItem(param1menu,4,false);
  253.          clemargs.format = 'n';
  254.          HiliteMenu(0);
  255.          break;
  256.        case 2:
  257.          CheckItem(param1menu,1,false);
  258.          CheckItem(param1menu,2,true);
  259.          CheckItem(param1menu,3,false);
  260.          CheckItem(param1menu,4,false);
  261.          clemargs.format = 'p';
  262.          HiliteMenu(0);
  263.          break;
  264.        case 3:
  265.          CheckItem(param1menu,1,false);
  266.          CheckItem(param1menu,2,false);
  267.          CheckItem(param1menu,3,true);
  268.          CheckItem(param1menu,4,false);
  269.          clemargs.format = 'g';
  270.          HiliteMenu(0);
  271.          break;
  272.        case 4:
  273.          CheckItem(param1menu,1,false);
  274.          CheckItem(param1menu,2,false);
  275.          CheckItem(param1menu,3,false);
  276.          CheckItem(param1menu,4,true);
  277.          clemargs.format = 't';
  278.          HiliteMenu(0);
  279.          break;
  280.       }
  281.       break;
  282.      }
  283.   }  
  284.      }  
  285.            }
  286.      }
  287.    }
  288.    else if (*opt == *opt2) {
  289.    
  290.      /********************************************************
  291.       * Release the resources that are occupied by the new menu 
  292.       *********************************************************/
  293.      ReleaseResource(mbar);
  294.      
  295.      /*************************
  296.       * Restore the old menu bar 
  297.       **************************/
  298.      SetMenuBar(ombar);
  299.    }
  300.  }
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.  
  308.